package cn.cloud9.activiti7.listener;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Before;
import org.junit.Test;

/**
 * @author OnCloud9
 * @description
 * @project activiti7
 * @date 2022年08月20日 下午 03:55
 */
public class ListenerApi {
    private ProcessEngine processEngine;
    private RepositoryService repositoryService;
    private RuntimeService runtimeService;
    private TaskService taskService;
    private HistoryService historyService;
    private ManagementService managementService;

    /**
     * 初始化预备资源
     */
    @Before
    public void loadingResource() {
        processEngine = ProcessEngines.getDefaultProcessEngine();
        repositoryService = processEngine.getRepositoryService();
        runtimeService = processEngine.getRuntimeService();
        taskService = processEngine.getTaskService();
        historyService = processEngine.getHistoryService();
        managementService = processEngine.getManagementService();
    }


    @Test
    public void deploymentProcess() {
        final Deployment deploy = repositoryService.createDeployment()
                .name("出差流程申请-监听器实现")
                .addClasspathResource("./bpmn/evection-listener.bpmn20.xml")
                .deploy();

        final String id = deploy.getId();
        final String name = deploy.getName();
        System.out.println("id = " + id);
        System.out.println("name = " + name);
    }

    @Test
    public void startProcess() {
        final ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("MyEvection-Listener");
    }
}
